package com.zytj.rs.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zytj.rs.dao.IReadRoomDao;
import com.zytj.rs.model.ReadRoom;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "资源管理")
@RestController
@RequestMapping("/read")
public class ReadRoomController {

	@Resource
	private IReadRoomDao roomDao;
	
	@ApiOperation(value = "显示资源" ,notes = "显示资源")
	@GetMapping
	public Map findAll() {
		List<ReadRoom> list = roomDao.findAll();
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("code", 0);
		map.put("date", list);
		return map;
	}
	@ApiOperation(value = "添加或修改资源" ,notes = "添加或修改资源")
	@PostMapping
	public String addOrEdit(@ModelAttribute ReadRoom read_room) {
		roomDao.save(read_room);
		return "保存成功";
	}
	
	@ApiOperation(value = "删除资源",notes = "删除资源")
	@PostMapping("{id}")
	public String del(int id) {
		roomDao.deleteById(id);;
		return "删除成功";
	}

	
	
}
